<? if( $_SESSION[ "JC_account_authority" ] && JC_authority( $_SESSION[ "JC_scheme" ][ $_REQUEST[ "JC_table" ] ][ "key" ][ "AIUD" ] ) ) { ?>

	<? if( ! intval( $_SESSION[ "JC_insert_multiple_" . $_REQUEST[ "JC_table" ] ] ) ) $_SESSION[ "JC_insert_multiple_" . $_REQUEST[ "JC_table" ] ] = "1"; ?>

	<? if( $_REQUEST[ "JC_mode" ] == "insert" ) { ?>

		<table>

			<tr>
				<th>Multiple	</th>
				<th>Form		</th>
				<th>Insert		</th>
			</tr>

			<tr>
				<td>
					<input
						type		= "text"
						value		= "<?= $_SESSION[ "JC_insert_multiple_" . $_REQUEST[ "JC_table" ] ] ?>"
						size		= "6"
						class		= "right"
						onchange	= "JC_session( 'JC_insert_multiple_<?= $_REQUEST[ "JC_table" ] ?>', this.value );"
					/></td>
				<td><a href="#this" class="form" onclick="location.reload( );">Form</a></td>
				<td>
					<a
						href		= "#this"
						title		= "If you click this, every record will be inserted."
						class		= "form"
						onclick		= "
							document.getElementById( 'JC_insert_form' ).value = 'every';
							document.getElementById( 'JC_insert' ).submit( );
						"
					>Insert</a>
				</td>
			</tr>

		</table><hr />

	<? } ?>


	<form id="JC_insert" target="JC_asynchronous" method="post">

		<input type="hidden" name="JC_query" value="insert" />
		<input type="hidden" name="JC_table" value="<?= $_REQUEST[ "JC_table" ] ?>" />
		<input type="hidden" id="JC_insert_form" name="JC_insert_form" value="every" />

		<table>

			<tr>

				<? if( $_REQUEST[ "JC_table" ] == "file" ) { ?>

					<th>File</th>

				<? } ?>

				<? foreach( $_SESSION[ "JC_scheme" ][ $_REQUEST[ "JC_table" ] ] as $key => $value ) { ?>

					<? if( $key == "comment"						) continue; ?>
					<? if( $key == "key"							) continue; ?>
					<? if( $key == "log"							) continue; ?>
					<? if( $key == "insert"							) continue; ?>
					<? if( $key == "update"							) continue; ?>
					<? if( $key == "delete"							) continue; ?>
					<? if( strpos( $key, " FKF" )					) continue; ?>
					<? if( ! JC_authority( $value[ "AIUD" ] )	) continue; ?>

					<th><?= JC_TH( $key ) ?></th>

				<? } ?>

				<th>Insert</th>

			</tr>



			<? for( $i = 0; $i < ( $_REQUEST[ "JC_mode" ] == "insert" ? intval( $_SESSION[ "JC_insert_multiple_" . $_REQUEST[ "JC_table" ] ] ) : 1 ); $i ++ ) { ?>

				<tr>

					<? if( $_REQUEST[ "JC_table" ] == "file" ) { ?>

						<td>

							<select
								id			= "JC_insert_file_<?= $i ?>"
								name		= "JC_insert_file_<?= $i ?>"
								onchange	= "
									document.getElementById( 'JC_insert_host_<?= $i ?>'		).selectedIndex = 0;
									document.getElementById( 'JC_insert_host_<?= $i ?>'		).options[ 0 ].selected = false;
									document.getElementById( 'JC_insert_type_<?= $i ?>'		).value = ( JC_insert_type[		this.value ] ? JC_insert_type[	this.value ] :  '' );
									document.getElementById( 'JC_insert_size_<?= $i ?>'		).value = ( JC_insert_size[		this.value ] ? JC_insert_size[	this.value ] :  '' );
									document.getElementById( 'JC_insert_width_<?= $i ?>'		).value = ( JC_insert_width[		this.value ] ? JC_insert_width[	this.value ] :  '' );
									document.getElementById( 'JC_insert_height_<?= $i ?>'	).value = ( JC_insert_height[	this.value ] ? JC_insert_height[	this.value ] :  '' );
								"
							>

								<script>

									var JC_insert_type	= new Array( );
									var JC_insert_size	= new Array( );
									var JC_insert_width	= new Array( );
									var JC_insert_height	= new Array( );

								</script>

								<option></option>

								<? foreach( JC_FT( ) as $key => $value ) { ?>

									<option value="<?= $key ?>"><?= $key ?></option>

									<script>

										JC_insert_type	[ "<?= $key ?>" ] = "<?= $value[ "type"		] ?>";
										JC_insert_size	[ "<?= $key ?>" ] = "<?= $value[ "size"		] ?>";
										JC_insert_width	[ "<?= $key ?>" ] = "<?= $value[ "width"	] ?>";
										JC_insert_height	[ "<?= $key ?>" ] = "<?= $value[ "height"	] ?>";

									</script>

								<? } ?>

							</select>

						</td>

					<? } ?>

					<? foreach( $_SESSION[ "JC_scheme" ][ $_REQUEST[ "JC_table" ] ] as $key => $value ) { ?>

						<? if( $key == "comment"						) continue; ?>
						<? if( $key == "key"							) continue; ?>
						<? if( $key == "log"							) continue; ?>
						<? if( $key == "insert"							) continue; ?>
						<? if( $key == "update"							) continue; ?>
						<? if( $key == "delete"							) continue; ?>
						<? if( strpos( $key, " FKF" )					) continue; ?>
						<? if( ! JC_authority( $value[ "AIUD" ] )	) continue; ?>



						<? if( $value[ "option" ] ) { // Option ?>

							<td>
								<select
									id		= "JC_insert_<?= $key ?>_<?= $i ?>"
									name	= "JC_insert_<?= $key ?>_<?= $i ?><?= $value[ "multiple" ] ? "[ ]" : "" ?>"
									title	= "<?= $value[ "type" ] ?>"
									onblur	= "if( this.value ) { this.title = this.value; } else { this.title = '<?= $value[ "type" ] ?>'; }"
									<?= $value[ "multiple" ] ? "size='2' multiple" : "" ?>
								>

									<? foreach( explode( ',', $value[ "option" ] ) as $option ) { ?>

										<option value="<?= trim( $option ) ?>"><?= trim( $option ) ?></option>

									<? } ?>

								</select>
							</td>

							<? continue; ?>

						<? } ?>



						<? if( strpos( $value[ "type" ], "int" ) !== false ) { // Integer ?>

							<td>
								<input
									id		= "JC_insert_<?= $key ?>_<?= $i ?>"
									name	= "JC_insert_<?= $key ?>_<?= $i ?>"
									title	= "<?= $value[ "type" ] ?>"
									size	= "<?= $value[ "size" ] ? $value[ "size" ] : 6 ?>"
									class	= "right"
									onblur	= "if( this.value ) { this.title = this.value; } else { this.title = '<?= $value[ "type" ] ?>'; }"
								/>
							</td>

						<? } ?>



						<? if( strpos( $value[ "type" ], "char" ) !== false || strpos( $value[ "type" ], "date" ) !== false ) { // Character or Date ?>

							<td>
								<input
									id		= "JC_insert_<?= $key ?>_<?= $i ?>"
									name	= "JC_insert_<?= $key ?>_<?= $i ?>"
									title	= "<?= $value[ "type" ] ?>"
									size	= "<?= $value[ "size" ] ? $value[ "size" ] : 12 ?>"
									onblur	= "if( this.value ) { this.title = this.value; } else { this.title = '<?= $value[ "type" ] ?>'; }"
								/>
							</td>

						<? } ?>



						<? if( $value[ "type" ] == "text" ) { // Text ?>

							<td>
								<textarea
									id		= "JC_insert_<?= $key ?>_<?= $i ?>"
									name	= "JC_insert_<?= $key ?>_<?= $i ?>"
									title	= "<?= $value[ "type" ] ?>"
									cols	= "<?= $value[ "size" ] ? $value[ "size" ] : "12" ?>"
									rows	= "2"
									onblur	= "if( this.value ) { this.title = this.value; } else { this.title = '<?= $value[ "type" ] ?>'; }"
								></textarea>
							</td>

						<? } ?>



					<? } ?>



					<td>
						<a
							href	= "#this"

							<? if( $_REQUEST[ "JC_mode" ] == "insert" ) { ?>

								title	= "If you click this, only this record will be inserted."

							<? } ?>

							class	= "form"
							onclick	= "

								<? if( $_REQUEST[ "JC_mode" ] == "insert" ) { ?>

									document.getElementById( 'JC_insert_form' ).value = '<?= $i ?>';

								<? } ?>

								document.getElementById( 'JC_insert' ).submit( );
							"
						>Insert</a>
					</td>

				<tr>

			<? } ?>

		</table><hr />

	</form>

<? } ?>
